<template>
  <div class="app-container home">
    <PanelGroup @handleSetLineChartData="handleSetLineChartData" />

    <el-divider />
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="margin-bottom: 20px">
        <el-card style="height: 400px">
          <div><BarChart v-if="barLoading" :msgData="receivable" /></div>
        </el-card>
      </el-col>

      <el-col :sm="24" :lg="12" style="margin-bottom: 20px">
        <el-card style="height: 400px">
          <div><BarChart v-if="donutLoading" :msgData="refund" /></div>
        </el-card>
      </el-col>
      <el-col :sm="24" :lg="12" style="margin-bottom: 20px">
        <el-card style="height: 400px">
          <div>
            <DonutChart v-if="performanceLoading" :msgData="performance" />
          </div>
        </el-card>
      </el-col>
      <el-col :sm="24" :lg="12" style="margin-bottom: 20px">
        <el-card style="height: 400px">
          <template #header>
            <div class="card-header">
              <span style="font-size: 18px; font-weight: bold">业绩排行榜</span>
            </div>
          </template>
          <div><Chats /></div>
        </el-card>
      </el-col>
      <el-col :sm="24" :lg="12">
        <StoreDaily />
      </el-col>
      <el-col :sm="24" :lg="12">
        <Cpdaily />
      </el-col>
    </el-row>
  </div>
</template>

<script setup name="Index">
import PanelGroup from "./dashboard/PanelGroup.vue";
import BarChart from "./dashboard/BarChart.vue";
import LineChart from "./dashboard/LineChart.vue";
import DonutChart from "./dashboard/DonutChart.vue";
import StoreDaily from "./dashboard/Stdaily.vue";
import Cpdaily from "./dashboard/Cpdaily.vue";
import Chats from "./dashboard/chats.vue";
import { getReceivable, getRefund, getPerformance } from "@/api";
import { onMounted } from "vue";
const version = ref("3.9.0");

function goTarget(url) {
  window.open(url, "__blank");
}
function handleSetLineChartData(type) {
  console.log(type);
}
//获取应收金额
const barLoading = ref(false);
const donutLoading = ref(false);
const performanceLoading = ref(false);
const performance = ref([]);
const receivable = ref({});
const refund = ref({});
onMounted(() => {
  //应收柱状图
  getReceivable().then((res) => {
    barLoading.value = true;
    receivable.value.txtKey = res.data.map((item) => item.itemName);
    receivable.value.txtValue = res.data.map((item) => item.payAmount);
    receivable.value.title = "应收金额";
  });
  //退款柱状图
  getRefund().then((res) => {
    donutLoading.value = true;
    refund.value.txtKey = res.data.map((item) => item.itemName);
    refund.value.txtValue = res.data.map((item) => item.payAmount);
    refund.value.title = "退款金额";
  });
  //业绩环形图
  getPerformance().then((res) => {
    performanceLoading.value = true;
    performance.value = [
      { value: res.data.servicePayTotalPrice, name: "出售" },
      { value: res.data.leaseOrderTotalPrice, name: "租赁" },
    ];
  });
});
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>
